﻿package mortal.game.view.market.myQiugou
{
    import Message.Game.*;
    import Message.Public.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.common.tools.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.market.*;
    import mortal.mvc.core.*;

    public class MktMyCellRenderner extends GCellRenderer
    {
        private var _item:BaseItem;
        private var _txtItemName:GTextFiled;
        private var _txtTime:GTextFiled;
        private var _bmpTotalPrice:GBitmap;
        private var _txtTotalPrice:GTextFiled;
        private var _bgTotalPrice:ScaleBitmap;
        private var _btnBroadcast:GButton;
        private var _btnSoldOut:GButton;
        private var _line:ScaleBitmap;
        private var _txtStrenLv:BitmapNumberText;
        private var _unit:int;

        public function MktMyCellRenderner()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._item = UIFactory.getUICompoment(BaseItem, 0, 3, this);
            this._item.setItemStyle(ItemStyleConst.Small, ImagesConst.PackItemBg, 2, 3);
            this._txtItemName = UIFactory.textField("mingzi", 45, 8, 100, 20, this);
            this._txtTime = UIFactory.textField("[剩余时间]", 45, 26, 100, 20, this);
            this._bgTotalPrice = UIFactory.bg(163, 13, 70, 22, this, ImagesConst.InputDisablBg);
            var _loc_1:* = GlobalStyle.textFormatHuang;
            _loc_1.align = TextFormatAlign.CENTER;
            this._txtTotalPrice = UIFactory.textField("", this._bgTotalPrice.x, this._bgTotalPrice.y, this._bgTotalPrice.width, this._bgTotalPrice.height, this, _loc_1);
            this._bmpTotalPrice = UIFactory.bitmap("", 0, 0, this);
            this._btnBroadcast = UIFactory.gButton("广播", 261, 13, 38, 22, this);
            this._btnSoldOut = UIFactory.gButton("下架", 301, 13, 38, 22, this);
            this._btnBroadcast.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._btnSoldOut.configEventListener(MouseEvent.CLICK, this.clickHandler);
            this._txtStrenLv = UIFactory.bitmapNumberText(15, 27, "FightInfoNum.png", 12, 15, -1, this);
            this._txtStrenLv.mouseEnabled = false;
            this._line = UIFactory.bg(0, 47, 320, 1, this, ImagesConst.SplitLine);
            this.unit = 1;
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            var obj:Object;
            var marketItem:SMarketItem;
            var str:String;
            var e:* = event;
            obj;
            marketItem = this.data as SMarketItem;
            if (e.currentTarget == this._btnBroadcast)
            {
                var onSelect:* = function (param1:int) : void
            {
                if (param1 == Alert.OK)
                {
                    if (!Cache.instance.role.enoughMoney(EPriceUnit._EPriceUnitCoin, MktModConfig.BroadcastCost))
                    {
                        MsgManager.showRollTipsMsg("金币不足");
                        return;
                    }
                    obj = {};
                    obj.recordId = marketItem.recordId;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.MarketBroadcast, obj));
                }
                return;
            }// end function
            ;
                str = "是否花费" + HTMLUtil.addColor(MktModConfig.BroadcastCost.toString(), GlobalStyle.colorHuang) + GameDefConfig.instance.getEPrictNameAddColoer(EPriceUnit._EPriceUnitCoin) + "宣传该条";
                str = str + (marketItem.recordType == EMarketRecordType._EMarketRecordSell ? ("寄售") : ("求购"));
                str = str + "信息";
                Alert.show(str, null, Alert.OK | Alert.CANCEL, null, onSelect);
            }
            else if (e.currentTarget == this._btnSoldOut)
            {
                if (this.data is SMarketItem)
                {
                    obj;
                    obj.recordId = marketItem.recordId;
                    if (marketItem.recordType == EMarketRecordType._EMarketRecordSell)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.MarketCancelSell, obj));
                    }
                    else if (marketItem.recordType == EMarketRecordType._EMarketRecordSeekBuy)
                    {
                        Dispatcher.dispatchEvent(new DataEvent(EventName.MarketCancelSeekBuy, obj));
                    }
                }
            }
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            var _loc_2:SMarketItem = null;
            var _loc_3:int = 0;
            var _loc_4:SPlayerItem = null;
            super.data = param1;
            if (param1 is SMarketItem)
            {
                _loc_2 = param1 as SMarketItem;
                if (_loc_2.code == EPriceUnit._EPriceUnitCoin || _loc_2.code == EPriceUnit._EPriceUnitGold)
                {
                    this._item.source = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitBigIcon(_loc_2.code));
                    this._txtItemName.htmlText = _loc_2.amount + GameDefConfig.instance.getEPrictUnitName(_loc_2.code);
                    this._item.amount = 0;
                }
                else
                {
                    _loc_4 = new SPlayerItem();
                    _loc_4.itemCode = _loc_2.code;
                    _loc_4.jsStr = _loc_2.itemExtend;
                    _loc_4.itemAmount = _loc_2.amount;
                    this._item.itemData = new ItemData(_loc_4);
                    this._txtItemName.htmlText = ItemsUtil.getItemName(this._item.itemData);
                }
                this.unit = _loc_2.sellUnit;
                this._txtTotalPrice.text = MktModConfig.getTotalPrice(_loc_2);
                _loc_3 = DateUtil.getSecondsDis(ClockManager.instance.nowDate, _loc_2.timeoutDt) / 60;
                if (_loc_3 < 0)
                {
                    this._txtTime.text = "已过期";
                }
                else if (_loc_3 > 60)
                {
                    this._txtTime.text = "剩余" + Math.ceil(_loc_3 / 60) + "小时";
                }
                else
                {
                    this._txtTime.text = "剩余" + _loc_3 + "分钟";
                }
                this.updateStrengLevel();
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._item.dispose(param1);
            this._txtItemName.dispose(param1);
            this._txtTime.dispose(param1);
            this._bgTotalPrice.dispose(param1);
            this._txtTotalPrice.dispose(param1);
            this._bmpTotalPrice.dispose(param1);
            this._btnBroadcast.dispose(param1);
            this._btnSoldOut.dispose(param1);
            this._txtStrenLv.dispose(param1);
            this._item = null;
            this._txtItemName = null;
            this._txtTime = null;
            this._bgTotalPrice = null;
            this._txtTotalPrice = null;
            this._bmpTotalPrice = null;
            this._btnBroadcast = null;
            this._btnSoldOut = null;
            this._txtStrenLv = null;
            return;
        }// end function

        private function updateStrengLevel() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:String = null;
            this._txtStrenLv.text = "";
            if (this._item && this._item.itemData)
            {
                if (ItemsUtil.isEquip(this._item.itemData))
                {
                    _loc_1 = this._item.itemData.extInfo == null ? (0) : (this._item.itemData.extInfo.strengthen);
                    _loc_2 = this._item.itemData.extInfo == null ? (0) : (this._item.itemData.extInfo.currentStrengthen);
                    if (_loc_1 == 0 && _loc_2 == 0)
                    {
                        _loc_3 = "";
                    }
                    else
                    {
                        _loc_3 = "+" + _loc_1;
                    }
                    this._txtStrenLv.text = _loc_3;
                }
                else if (ItemsUtil.isOtherEquip(this._item.itemData) && this._item.itemData.itemInfo.itemLevel)
                {
                    this._txtStrenLv.text = "+" + this._item.itemData.itemInfo.itemLevel;
                }
                this._txtStrenLv.x = 41 - this._txtStrenLv.width;
                this._txtStrenLv.y = 41 - this._txtStrenLv.height;
            }
            else
            {
                this._txtStrenLv.text = "";
            }
            return;
        }// end function

        public function set unit(param1:int) : void
        {
            this._unit = param1;
            this._bmpTotalPrice.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getEPrictUnitImg(param1));
            this._bmpTotalPrice.x = this._bgTotalPrice.x - 22;
            this._bmpTotalPrice.y = this._bgTotalPrice.y + (this._bgTotalPrice.height - this._bmpTotalPrice.height) / 2;
            return;
        }// end function

    }
}
